Link to this headingShamir’s Secret Sharing Scheme (SSSS)
If the share is a k-degree polynomial then it needs k+1 points to generate the original polynomial with the secret.
If you needs 5 partial keys then you just have to generate 5 points that are on the polynomial.
Link to this headingMath
You use Lagrange polynomials To create polynomials that are Zero at each other point other than 1 specific point.
Using this you can multiply the polynomials together to create a function that goes through each of the points that were provided.
Link to this headingUsage
#Generate Key
=
#Generate Shares
=
#Print Shares
#Use Two shares to get secret
=
# 2d8a50d47df6fee7e8e8b7e2baf6e00b
# Index #1: b'77de49da4c10496546fed2fa8a013dcd'
# Index #2: b'992262c81e3b91e2b4c47dd2db195b81'
# Index #3: b'c3767bc62fdd26601ad218caebee8647'
# Index #4: b'44da34ecba6c20ed50b1238279299780'
# Index #5: b'1e8e2de28b8a976ffea7469a49de4a46'
# 2d8a50d47df6fee7e8e8b7e2baf6e00b
Link to this headingImplementation
= 0
+= *
return
# Reconstruct the secret from shares
= 0
=
, =
# Calculate Lagrange basis polynomial L_i(0) - we evaluate at x=0 to get the secret
= 1
= 1
, =
= %
= %
# Calculate L_i(0) = numerator / denominator
= %
= %
return
= 6
= 3
= 2 ** 31 - 1
=
#Get Random Numbers
=
=
#Generate Shares
=
=
=
# Print shares
# Reconstruct the secret from shares
=
# Secret: 90105115
# Polynomial: y = 90105115*x^0 + 116990366*x^1 + 219152435*x^2
# Point: (1, 426247916)
# Point: (2, 1200695587)
# Point: (3, 2413448128)
# Point: (4, 4064505539)
# Point: (5, 6153867820)
# Point: (6, 8681534971)
# Reconstructed Secret: 90105115
Link to this headingImplementation with AES
=
# Convert secret to bytes
=
#Generate Key
=
#Generate Shares
=
#Print Shares
# Encrypt the secret using AES
=
, =
#Print Shares
# Reconstruct the key from shares
=
# Decrypt the secret using the reconstructed key
=
=
# 96f87ae4861e1763acebdd4213cd4139
# Index #1: b'1d2481743b3a39d1e6322b11f115ec1e'
# Index #2: b'81418dc5fc564a07395831e5d67c1bf0'
# Index #3: b'0a9d7655417264b57381c7b634a4b6d7'
# Index #4: b'b98b94a6728eadaa878c040d98aff4ab'
# Index #5: b'32576f36cfaa8318cd55f25e7a77598c'
# IV: 62eea5e3ac9633d2d2802a502247cf1f, Ciphertext: eacd662ee1e732e2040131d3f8fd68a2b81166138855aa03c6, Tag: 4f0461bb8efad4e8547e64c1bfb8c9e1
# Share Index #1: b'1d2481743b3a39d1e6322b11f115ec1e', Nonce: 62eea5e3ac9633d2d2802a502247cf1f, Encrypted_data: eacd662ee1e732e2040131d3f8fd68a2b81166138855aa03c6, Tag: 4f0461bb8efad4e8547e64c1bfb8c9e1
# Share Index #2: b'81418dc5fc564a07395831e5d67c1bf0', Nonce: 62eea5e3ac9633d2d2802a502247cf1f, Encrypted_data: eacd662ee1e732e2040131d3f8fd68a2b81166138855aa03c6, Tag: 4f0461bb8efad4e8547e64c1bfb8c9e1
# Share Index #3: b'0a9d7655417264b57381c7b634a4b6d7', Nonce: 62eea5e3ac9633d2d2802a502247cf1f, Encrypted_data: eacd662ee1e732e2040131d3f8fd68a2b81166138855aa03c6, Tag: 4f0461bb8efad4e8547e64c1bfb8c9e1
# Share Index #4: b'b98b94a6728eadaa878c040d98aff4ab', Nonce: 62eea5e3ac9633d2d2802a502247cf1f, Encrypted_data: eacd662ee1e732e2040131d3f8fd68a2b81166138855aa03c6, Tag: 4f0461bb8efad4e8547e64c1bfb8c9e1
# Share Index #5: b'32576f36cfaa8318cd55f25e7a77598c', Nonce: 62eea5e3ac9633d2d2802a502247cf1f, Encrypted_data: eacd662ee1e732e2040131d3f8fd68a2b81166138855aa03c6, Tag: 4f0461bb8efad4e8547e64c1bfb8c9e1
# Reconstructed Key: 96f87ae4861e1763acebdd4213cd4139
# Decrypted Secret: This is a secret message.
Link to this headingSecurity
Ensure that x != 0 because then a term will be removed making it easier to reconstruct the secret.
Ensure that there is not a repeat point.